import textfsm
import os
import pandas as pd
from ntc_templates.parse import parse_output
from pathlib import Path
# import xlwings as xw
# import pyperclip

os.environ["NTC_TEMPLATES_DIR"] = r"D:\code\ted\TED-2023\templates"
os.chdir(r'C:\Users\Desktop')

def output(platform, command, file_name=None):
    text = parse_output(platform=platform, command=command, data=output_data)
    df = pd.DataFrame(text)
    df['Device'] = file_name

    # print('-------------------------------------')
    # print(df)
    # print('-------------------------------------') 

    # df.to_clipboard(sep='  ',index=False)  
    # df.to_excel(file_name, index=False)
    # book = xw.Book(file_name)
    return df



if __name__ == "__main__":
    folder_path = r'C:\Users\Desktop\WOM Data\1004\arp-collect\20231004000028\all'
    os.chdir(folder_path)
    files = os.listdir(folder_path)
    count = 1

    lst = []
    # path = Path(file)
    for file in files:
        with open(file,'r', encoding='gb18030',errors='ignore') as output_file:
            output_data = output_file.read()
            # print(output_data)

        # output('alcatel_sros', 'show service using', 'service.xlsx')
        lst.append(output('huawei_vrp', 'display arp all',file))

        print(len(files) - count)
        count += 1

    merged_df = pd.concat(lst)
    merged_df.to_excel('all_arp.xlsx', index=False)
    print("Done!")
